$(function(){
	var preg = /^[0-9A-Za-z_]{6,16}$/;
	var s1 = false;
	var s2 = false;

	$('form').submit(function(){
		if (s1&&s2) {
			return true;
		}
		return false;
	})

	$('form #password').focus(function(){
		$(this).parent().next().children('span').html('<font size=1 color="#333">请输入6-16位以数组、字母、下划线的组合，不允许有空格</font>');
	})

	$('form #password').blur(function(){
		$(this).parent().next().children('span').html('');
		if (preg.test($(this).val())) {
			$('#success_error').attr('class','alert alert-success');
			$('#success_error').css('display','block');
			$('#success_error strong').html('密码可用');
			s1 = true;
		} else {
			$('#success_error').attr('class','alert alert-danger');
			$('#success_error').css('display','block');
			$('#success_error strong').html('密码不符合规则');
			s1 = false;
		}
		
	})

	$('form #passwordRepeat').focus(function(){
		$(this).parent().next().children('span').html('<font size=1 color="#333">请与上面密码保持一致</font>');
	})

	$('form #passwordRepeat').blur(function(){
		$(this).parent().next().children('span').html('');
		if (preg.test($(this).val()) && $('form #password').val() == $('form #passwordRepeat').val()) {
			$('#success_error').attr('class','alert alert-success');
			$('#success_error').css('display','block');
			$('#success_error strong').html('两次密码一致');
			s2 = true;
		} else {
			$('#success_error').attr('class','alert alert-danger');
			$('#success_error').css('display','block');
			$('#success_error strong').html('不符合规则或两次密码不一致');
			s2 = false;
		}
	})

	$('#success_error').click(function(){
		$(this).css('display','none');
	})
})